bitkeeper revision 1.220 (3eba7140Xm9JLEfxz1hmvq2pg7H5UA)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 8 May 2003 15:01:20 +0000 (15:01 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 8 May 2003 15:01:20 +0000 (15:01 +0000)
sched.h, domain.c, dom0_ops.c:
  Robustify domain creation and building.

xen/common/dom0_ops.c
xen/common/domain.c
xen/include/xeno/sched.h

index fb8d44429e249fbf809935b0a4b816374bf0cd8a..7a13d135c5f246c79b915bb5c69d64b59e3710fa 100644 (file)
@@ -20,7 +20,9 @@ extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int);
 static unsigned int get_domnr(void)
 {
     static unsigned int domnr = 0;
-    return ++domnr;
+    do { domnr = (domnr+1) & ((1<<20)-1); }
+    while ( find_domain_by_id(domnr) != NULL );
+    return domnr;
 }
 
 static void build_page_list(struct task_struct *p)
@@ -75,6 +77,9 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     case DOM0_STARTDOMAIN:
     {
         struct task_struct * p = find_domain_by_id(op.u.meminfo.domain);
+        ret = -EINVAL;
+        if ( (p == NULL) || !(p->flags & PF_CONSTRUCTED) )
+            break;
         wake_up(p);
         reschedule(p);
         ret = p->domain;
index e2a8306357583350485f49d63f722a66e1aadc70..3a83aa4d109f8f486669406cae02f7722fe1b27d 100644 (file)
@@ -48,7 +48,7 @@ struct task_struct *do_newdomain(unsigned int dom_id, unsigned int cpu)
     p->domain    = dom_id;
     p->processor = cpu;
 
-    sprintf (p->name, "Domain-%d", dom_id);
+    sprintf(p->name, "Domain-%d", dom_id);
 
     spin_lock_init(&p->blk_ring_lock);
     spin_lock_init(&p->page_lock);
@@ -331,6 +331,9 @@ int final_setup_guestos(struct task_struct * p, dom_meminfo_t * meminfo)
     net_vif_t *net_vif;
     int i;
 
+    if ( (p->flags & PF_CONSTRUCTED) )
+        return -EINVAL;
+
     /* High entries in page table must contain hypervisor
      * mem mappings - set them up.
      */
@@ -386,11 +389,6 @@ int final_setup_guestos(struct task_struct * p, dom_meminfo_t * meminfo)
     virt_startinfo_addr->dom_id = p->domain;
     virt_startinfo_addr->flags  = IS_PRIV(p) ? SIF_PRIVILEGED : 0;
 
-    if( virt_startinfo_addr->mod_len )
-       printk("Initrd module present %08lx (%08lx)\n",
-               virt_startinfo_addr->mod_start, 
-               virt_startinfo_addr->mod_len);  
     /* Add virtual network interfaces and point to them in startinfo. */
     while (meminfo->num_vifs-- > 0) {
         net_vif = create_net_vif(p->domain);
@@ -417,6 +415,8 @@ int final_setup_guestos(struct task_struct * p, dom_meminfo_t * meminfo)
     __asm__ __volatile__ (
         "mov %%eax,%%cr3" : : "a" (pagetable_val(current->mm.pagetable)));    
     __sti();
+
+    p->flags |= PF_CONSTRUCTED;
     
     new_thread(p, 
                (unsigned long)meminfo->virt_load_addr, 
@@ -461,6 +461,7 @@ int setup_guestos(struct task_struct *p, dom0_newdomain_t *params,
 
     /* Sanity! */
     if ( p->domain != 0 ) BUG();
+    if ( (p->flags & PF_CONSTRUCTED) ) BUG();
 
     /*
      * This is all a bit grim. We've moved the modules to the "safe" physical 
@@ -700,6 +701,8 @@ int setup_guestos(struct task_struct *p, dom0_newdomain_t *params,
     __write_cr3_counted(pagetable_val(current->mm.pagetable));
     __sti();
 
+    p->flags |= PF_CONSTRUCTED;
+
     new_thread(p, 
                (unsigned long)virt_load_address, 
                (unsigned long)virt_stack_address, 
index c5ab334b0061ce797a53a387ff7ac8ef1253484c..f696b5ab5674dbaa01d74d6230a209ff7b88e534 100644 (file)
@@ -58,6 +58,7 @@ extern struct mm_struct init_mm;
 #define PF_DONEFPUINIT  0x1  /* Has the FPU been initialised for this task? */
 #define PF_USEDFPU      0x2  /* Has this task used the FPU since last save? */
 #define PF_GUEST_STTS   0x4  /* Has the guest OS requested 'stts'?          */
+#define PF_CONSTRUCTED  0x8  /* Has the guest OS been fully built yet? */
 
 #include <xeno/vif.h>
 #include <xeno/block.h>